package entities;

import javax.persistence.*;
import java.sql.Timestamp;

@javax.persistence.Table(name = "bids", schema = "", catalog = "bidsystem")
@Entity
public class BidsEntity {
    private int id;

    @javax.persistence.Column(name = "id")
    @Id
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private Timestamp dateCreated;

    @javax.persistence.Column(name = "date_created")
    @Basic
    public Timestamp getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Timestamp dateCreated) {
        this.dateCreated = dateCreated;
    }

    private float price;

    @javax.persistence.Column(name = "price")
    @Basic
    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    private UsersEntity user;

    @ManyToOne()
    @JoinColumn(name = "user_id", nullable = false)
    public UsersEntity getUser() {
        return this.user;
    }

    public void setUser(UsersEntity user) {
        this.user = user;
    }

    private ProductsEntity product;

    @ManyToOne()
    @JoinColumn(name = "prod_id", nullable = false)
    public ProductsEntity getProduct() {
        return product;
    }

    public void setProduct(ProductsEntity product) {
        this.product = product;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BidsEntity that = (BidsEntity) o;

        if (id != that.id) return false;
        if (Float.compare(that.price, price) != 0) return false;
        if (dateCreated != null ? !dateCreated.equals(that.dateCreated) : that.dateCreated != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (dateCreated != null ? dateCreated.hashCode() : 0);
        result = 31 * result + (price != +0.0f ? Float.floatToIntBits(price) : 0);
        return result;
    }
}
